<!DOCTYPE html>
<html>

<head>
  <title>Quarkus - Qute Reference Guide</title>
  <script id="adobe_dtm" src="https://www.redhat.com/dtm.js" type="text/javascript"></script>
  <script src="/assets/javascript/highlight.pack.js" type="text/javascript"></script>
  <META HTTP-EQUIV='Content-Security-Policy' CONTENT="default-src 'none'; script-src 'self' 'unsafe-eval' 'sha256-ANpuoVzuSex6VhqpYgsG25OHWVA1I+F6aGU04LoI+5s=' 'sha256-ipy9P/3rZZW06mTLAR0EnXvxSNcnfSDPLDuh3kzbB1w=' js.bizographics.com https://www.redhat.com assets.adobedtm.com jsonip.com https://ajax.googleapis.com https://www.googletagmanager.com https://www.google-analytics.com https://use.fontawesome.com; style-src 'self' https://fonts.googleapis.com https://use.fontawesome.com; img-src 'self' *; media-src 'self' ; frame-src https://www.googletagmanager.com https://www.youtube.com; frame-ancestors 'none'; base-uri 'none'; object-src 'none'; form-action 'none'; font-src 'self' https://use.fontawesome.com https://fonts.gstatic.com;">
  <META HTTP-EQUIV='X-Frame-Options' CONTENT="DENY">
  <META HTTP-EQUIV='X-XSS-Protection' CONTENT="1; mode=block">
  <META HTTP-EQUIV='X-Content-Type-Options' CONTENT="nosniff">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="description" content="Quarkus: Supersonic Subatomic Java">
  <meta name="twitter:card" content="summary_large_image">
  <meta name="twitter:site" content="@QuarkusIO"> 
  <meta name="twitter:creator" content="@QuarkusIO">
  <meta property="og:url" content="https://quarkus.io/guides/qute-reference" />
  <meta property="og:title" content="Quarkus - Qute Reference Guide" />
  <meta property="og:description" content="Quarkus: Supersonic Subatomic Java" />
  <meta property="og:image" content="/assets/images/quarkus_card.png" />
  <link rel="canonical" href="https://quarkus.io/guides/qute-reference">
  <link rel="shortcut icon" type="image/png" href="/favicon.ico" >
  <link rel="stylesheet" href="https://quarkus.io/guides/stylesheet/config.css" />
  <link rel="stylesheet" href="/assets/css/main.css" />
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  <link rel="alternate" type="application/rss+xml"  href="https://quarkus.io/feed.xml" title="Quarkus">
  <script src="https://quarkus.io/assets/javascript/goan.js" type="text/javascript"></script>
  <script src="https://quarkus.io/assets/javascript/hl.js" type="text/javascript"></script>
</head>

<body class="guides">
  <!-- Google Tag Manager (noscript) -->
  <noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-NJWS5L"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
  <!-- End Google Tag Manager (noscript) -->

  <div class="nav-wrapper">
  <div class="grid-wrapper">
    <div class="width-12-12">
      <input type="checkbox" id="checkbox" />
      <nav id="main-nav" class="main-nav">
  <div class="container">
    <div class="logo-wrapper">
      
        <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_600px_reverse.png" class="project-logo" title="Quarkus"></a>
      
    </div>
    <label class="nav-toggle" for="checkbox">
      <i class="fa fa-bars"></i>
    </label>
    <div id="menu" class="menu">
      <span>
        <a href="/get-started/" class="">Get Started</a>
      </span>
      <span>
        <a href="/guides/" class="active">Guides</a>
      </span>
      <span>
        <a href="/community/" class="">Community</a>
      </span>
      <span>
        <a href="/support/" class="">Support</a>
      </span>
      <span>
        <a href="/blog/" class="">Blog</a>
      </span>
      <span>
        <a href="https://code.quarkus.io" class="button-cta secondary white">Start Coding</a>
      </span>
    </div>
  </div>
      </nav>
    </div>
  </div>
</div>

  <div class="content">
    <div class="guide">
  <div class="width-12-12">
    <h1 class="text-caps">Quarkus - Qute Reference Guide</h1>
    <div class="hide-mobile toc"><ul class="sectlevel1">
<li><a href="#hello-world-example">1. Hello World Example</a></li>
<li><a href="#core-features">2. Core Features</a>
<ul class="sectlevel2">
<li><a href="#syntax-and-building-blocks">2.1. Syntax and Building Blocks</a></li>
<li><a href="#identifiers">2.2. Identifiers</a></li>
<li><a href="#removing-standalone-lines-from-the-template">2.3. Removing Standalone Lines From the Template</a></li>
<li><a href="#engine-configuration">2.4. Engine Configuration</a></li>
</ul>
</li>
<li><a href="#quarkus_integration">3. Quarkus Integration</a>
<ul class="sectlevel2">
<li><a href="#template-variants">3.1. Template Variants</a></li>
<li><a href="#injecting-beans-directly-in-templates">3.2. Injecting Beans Directly In Templates</a></li>
<li><a href="#parameter_declarations">3.3. Parameter Declarations</a></li>
<li><a href="#template_extension_methods">3.4. Template Extension Methods</a></li>
<li><a href="#template_data">3.5. @TemplateData</a></li>
<li><a href="#resteasy_integration">3.6. RESTEasy Integration</a></li>
<li><a href="#development-mode">3.7. Development Mode</a></li>
<li><a href="#type-safe-message-bundles">3.8. Type-safe Message Bundles</a></li>
<li><a href="#configuration-reference">3.9. Configuration Reference</a></li>
</ul>
</li>
</ul></div>
    <div>
      <div id="preamble">
<div class="sectionbody">
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
<div class="paragraph">
<p>This technology is considered experimental.</p>
</div>
<div class="paragraph">
<p>In <em>experimental</em> mode, early feedback is requested to mature the idea.
There is no guarantee of stability nor long term presence in the platform until the solution matures.
Feedback is welcome on our <a href="https://groups.google.com/d/forum/quarkus-dev">mailing list</a> or as issues in our <a href="https://github.com/quarkusio/quarkus/issues">GitHub issue tracker</a>.</p>
</div>
<div class="paragraph">
<p>For a full list of possible extension statuses, check our <a href="https://quarkus.io/faq/#extension-status">FAQ entry</a>.</p>
</div>
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="hello-world-example"><a class="anchor" href="#hello-world-example"></a>1. Hello World Example</h2>
<div class="sectionbody">
<div class="paragraph">
<p>In this example, we&#8217;d like to demonstrate the basic workflow when working with Qute templates.
Let&#8217;s start with a simple hello world example.
We will always need some <strong>template contents</strong>:</p>
</div>
<div class="listingblock">
<div class="title">hello.html</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
  &lt;p&gt;Hello {name}! <i class="conum" data-value="1"></i><b>(1)</b>
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>{name}</code> is a value expression that is evaluated when the template is rendered.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Then, we will need to parse the contents into a <strong>template definition</strong> Java object.
A template definition is an instance of <code>io.quarkus.qute.Template</code>.</p>
</div>
<div class="paragraph">
<p>If using Qute "standalone" you&#8217;ll need to create an instance of <code>io.quarkus.qute.Engine</code> first.
The <code>Engine</code> represents a central point for template management with dedicated configuration.
Let&#8217;s use the convenient builder:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">Engine engine = Engine.builder().addDefaults().build();</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
In Quarkus, there is a preconfigured <code>Engine</code> available for injection - see <a href="#quarkus_integration">Quarkus Integration</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>If we have an <code>Engine</code> instance we could parse the template contents:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">Template helloTemplate = engine.parse(helloHtmlContent);</code></pre>
</div>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
In Quarkus, you can simply inject the template definition. The template is automatically parsed and cached - see <a href="#quarkus_integration">Quarkus Integration</a>.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Finally, we will create a <strong>template instance</strong>, set the data and render the output:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">// Renders &lt;html&gt;&lt;p&gt;Hello Jim!&lt;/p&gt;&lt;/html&gt;
helloTemplate.data("name", "Jim").render(); <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>Template.data(String, Object)</code> is a convenient method that creates a template instance and sets the data in one step.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>So the workflow is simple:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Create template contents (<code>hello.html</code>),</p>
</li>
<li>
<p>Parse template definition (<code>io.quarkus.qute.Template</code>),</p>
</li>
<li>
<p>Create template instance (<code>io.quarkus.qute.TemplateInstance</code>),</p>
</li>
<li>
<p>Render output.</p>
</li>
</ol>
</div>
<div class="paragraph">
<p>The <code>Engine</code> is able to cache the definitions so that it&#8217;s not necessary to parse the contents again and again.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In Quarkus, the caching is done automatically.
</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect1">
<h2 id="core-features"><a class="anchor" href="#core-features"></a>2. Core Features</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="syntax-and-building-blocks"><a class="anchor" href="#syntax-and-building-blocks"></a>2.1. Syntax and Building Blocks</h3>
<div class="paragraph">
<p>The dynamic parts of a template include:</p>
</div>
<div class="ulist">
<ul>
<li>
<p><strong>Comment</strong></p>
<div class="ulist">
<ul>
<li>
<p>Starts with <code>{!</code> and ends with <code>!}</code>:  <code>{! This is a comment !}</code>,</p>
</li>
<li>
<p>Could be multi-line,</p>
</li>
<li>
<p>May contain expressions and sections: <code>{! {#if true} !}</code>.</p>
</li>
</ul>
</div>
</li>
<li>
<p><strong>Expression</strong></p>
<div class="ulist">
<ul>
<li>
<p>Outputs the evaluated value,</p>
</li>
<li>
<p>Simple properties: <code>{foo}</code>, <code>{item.name}</code>,</p>
</li>
<li>
<p>Virtual methods: <code>{item.get(name)}</code>, <code>{name ?: 'John'}</code>,</p>
</li>
<li>
<p>With namespace: <code>{inject:colors}</code>.</p>
</li>
</ul>
</div>
</li>
<li>
<p><strong>Section</strong></p>
<div class="ulist">
<ul>
<li>
<p>May contain expressions and sections: <code>{#if foo}{foo.name}{/if}</code>,</p>
</li>
<li>
<p>The name in the closing tag is optional: <code>{#if active}ACTIVE!{/}</code>,</p>
</li>
<li>
<p>Can be empty: <code>{#myTag image=true /}</code>,</p>
</li>
<li>
<p>May declare nested section blocks: <code>{#if item.valid} Valid. {#else} Invalid. {/if}</code> and decide which block to render.</p>
</li>
</ul>
</div>
</li>
<li>
<p><strong>Unparsed Character Data</strong></p>
<div class="ulist">
<ul>
<li>
<p>Starts with <code>{[</code> and ends with <code>]}</code>: <code>{[ &lt;script&gt;if(true){alert('Qute is cute!')};&lt;/script&gt; ]}</code>,</p>
</li>
<li>
<p>Could be multi-line,</p>
</li>
<li>
<p>Used to mark the content that should be rendered but not parsed.</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="identifiers"><a class="anchor" href="#identifiers"></a>2.2. Identifiers</h3>
<div class="paragraph">
<p>Expressions/tags must start with a curly bracket (<code>{</code>) followed by a valid identifier.
A valid identifier is a digit, an alphabet character, underscore (<code>_</code>), or a section command (<code>#</code>).
Expressions/tags starting with an invalid identifier are ignored.
A closing curly bracket (<code>}</code>) is ignored if not inside an expression/tag.</p>
</div>
<div class="listingblock">
<div class="title">hello.html</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
   &lt;body&gt;
   {_foo}       <i class="conum" data-value="1"></i><b>(1)</b>
   {  foo}      <i class="conum" data-value="2"></i><b>(2)</b>
   {{foo}}      <i class="conum" data-value="3"></i><b>(3)</b>
   {"foo":true} <i class="conum" data-value="4"></i><b>(4)</b>
   &lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Evaluated: expression starts with underscore.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Ignored: expression starts with whitespace.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Ignored: expression starts with <code>{</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Ignored: expression starts with <code>"</code>.</td>
</tr>
</table>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
It is also possible to use escape sequences <code>\{</code> and <code>\}</code> to insert delimiters in the text. In fact, an escape sequence is usually only needed for the start delimiter, ie. <code>\{foo}</code> will be rendered as <code>{foo}</code> (no evaluation will happen).
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="removing-standalone-lines-from-the-template"><a class="anchor" href="#removing-standalone-lines-from-the-template"></a>2.3. Removing Standalone Lines From the Template</h3>
<div class="paragraph">
<p>By default, Qute parser removes standalone lines from the template output.
A <strong>standalone line</strong> is a line that contains at least one section tag (e.g. <code>{#each}</code> and <code>{/each}</code>) or parameter declaration (e.g. <code>{@org.acme.Foo foo}</code>) but no expression and non-whitespace character.
In other words, a line that contains no section tag or a parameter declaration is <strong>not</strong> a standalone line.
Likewise, a line that contains an <em>expression</em> or a <em>non-whitespace character</em> is <strong>not</strong> a standalone line.</p>
</div>
<div class="listingblock">
<div class="title">Template Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
  &lt;body&gt;
     &lt;ul&gt;
     {#for item in items} <i class="conum" data-value="1"></i><b>(1)</b>
       &lt;li&gt;{item.name} {#if item.active}{item.price}{/if}&lt;/li&gt;  <i class="conum" data-value="2"></i><b>(2)</b>
                          <i class="conum" data-value="3"></i><b>(3)</b>
     {/for}               <i class="conum" data-value="4"></i><b>(4)</b>
     &lt;/ul&gt;
   &lt;body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This is a standalone line and will be removed.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Not a standalone line - contains an expression and non-whitespace characters</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Not a standalone line - contains no section tag/parameter declaration</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>This is a standalone line.</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="title">Default Output</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
  &lt;body&gt;
     &lt;ul&gt;
       &lt;li&gt;Foo 100&lt;/li&gt;

     &lt;/ul&gt;
   &lt;body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>The default behavior can be disabled by setting the property <code>quarkus.qute.remove-standalone-lines</code> to <code>false</code>.
In this case, all whitespace characters from a standalone line will be printed to the output.</p>
</div>
<div class="listingblock">
<div class="title">Output with <code>quarkus.qute.remove-standalone-lines=false</code></div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
  &lt;body&gt;
     &lt;ul&gt;

       &lt;li&gt;Foo 100&lt;/li&gt;


     &lt;/ul&gt;
   &lt;body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="sect3">
<h4 id="expressions"><a class="anchor" href="#expressions"></a>2.3.1. Expressions</h4>
<div class="paragraph">
<p>An expression outputs a value.
It consists of one or more parts separated by dot (dot notation) or square brackets (bracket notation).
In the <code>object[property_name]</code> syntax, the <code>property_name</code> has to be a non-null <a href="#literals">literal</a> value.
An expression could start with an optional namespace followed by a colon (<code>:</code>).</p>
</div>
<div class="listingblock">
<div class="title">Expressions Example</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{name} <i class="conum" data-value="1"></i><b>(1)</b>
{item.name} <i class="conum" data-value="2"></i><b>(2)</b>
{item['name']} <i class="conum" data-value="3"></i><b>(3)</b>
{global:colors} <i class="conum" data-value="4"></i><b>(4)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>no namespace, one part: <code>name</code></td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>no namespace, two parts: <code>item</code>, <code>name</code></td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>equivalent to <code>{item.name}</code> but using the bracket notation</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>namespace <code>global</code>, one part: <code>colors</code></td>
</tr>
</table>
</div>
<div class="paragraph">
<p>A part of an expression could be a <em>virtual method</em> in which case the name can be followed by a list of comma-separated parameters in parentheses:</p>
</div>
<div class="listingblock">
<div class="title">Virtual Method Example</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{item.getLabels(1)} <i class="conum" data-value="1"></i><b>(1)</b>
{name or 'John'} <i class="conum" data-value="2"></i><b>(2)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>no namespace, two parts - <code>item</code>, <code>getLabels(1)</code>, the second part is a virtual method with name <code>getLabels</code> and params <code>1</code></td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>infix notation, translated to <code>name.or('John')</code>; no namespace, two parts - <code>name</code>, <code>or('John')</code></td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
A parameter of a virtual method can be a <a href="#literals">literal</a> value.
</td>
</tr>
</table>
</div>
<div class="sect4">
<h5 id="literals"><a class="anchor" href="#literals"></a>2.3.1.1. Supported Literals</h5>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 50%;">
<col style="width: 50%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Literal</th>
<th class="tableblock halign-left valign-top">Examples</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>true</code>, <code>false</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">null</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>null</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>'value'</code>, <code>"string"</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">integer</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>1</code>, <code>-5</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">long</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>1l</code>, <code>-5L</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">double</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>1D</code>, <code>-5d</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">float</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>1f</code>, <code>-5F</code></p></td>
</tr>
</tbody>
</table>
</div>
<div class="sect4">
<h5 id="resolution"><a class="anchor" href="#resolution"></a>2.3.1.2. Resolution</h5>
<div class="paragraph">
<p>The first part of the expression is always resolved against the <a href="#current_context_object">current context object</a>.
If no result is found for the first part it&#8217;s resolved against the parent context object (if available).
For an expression that starts with a namespace the current context object is found using all the available <code>NamespaceResolver</code>s.
For an expression that does not start with a namespace the current context object is <strong>derived from the position</strong> of the tag.
All other parts are resolved using <code>ValueResolver</code>s against the result of the previous resolution.</p>
</div>
<div class="paragraph">
<p>For example, expression <code>{name}</code> has no namespace and single part - <code>name</code>.
The "name" will be resolved using all available value resolvers against the current context object.
However, the expression <code>{global:colors}</code> has the namespace <code>global</code> and single part - <code>colors</code>.
First, all available <code>NamespaceResolver</code>s will be used to find the current context object.
And afterwards value resolvers will be used to resolve "colors" against the context object found.</p>
</div>
</div>
<div class="sect4">
<h5 id="current_context_object"><a class="anchor" href="#current_context_object"></a>2.3.1.3. Current Context</h5>
<div class="paragraph">
<p>If an expression does not specify a namespace the current context object is derived from the position of the tag.
By default, the current context object represents the data passed to the template instance.
However, sections may change the current context object.
A typical example is the for/each loop - during iteration the content of the section is rendered with each element as the current context object:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#each items}
  {count}. {it.name} <i class="conum" data-value="1"></i><b>(1)</b>
{/each}

{! Another form of iteration... !}
{#for item in items}
  {count}. {item.name} <i class="conum" data-value="2"></i><b>(2)</b>
{/for}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>it</code> is an implicit alias. <code>name</code> is resolved against the current iteration element.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Loop with an explicit alias <code>item</code>.</td>
</tr>
</table>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
<div class="paragraph">
<p>Data passed to the template instance are always accessible using the <code>data</code> namespace.
This could be useful to access data for which the key is overridden:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
{item.name} <i class="conum" data-value="1"></i><b>(1)</b>
&lt;ul&gt;
{#for item in item.getDerivedItems()} <i class="conum" data-value="2"></i><b>(2)</b>
  &lt;li&gt;
  {item.name} <i class="conum" data-value="3"></i><b>(3)</b>
  is derived from
  {data:item.name} <i class="conum" data-value="4"></i><b>(4)</b>
  &lt;/li&gt;
{/for}
&lt;/ul&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>item</code> is passed to the template instance as a data object.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Iterate over the list of derived items.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td><code>item</code> is an alias for the iterated element.</td>
</tr>
<tr>
<td><i class="conum" data-value="4"></i><b>4</b></td>
<td>Use the <code>data</code> namespace to access the <code>item</code> data object.</td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="built-in-operators"><a class="anchor" href="#built-in-operators"></a>2.3.1.4. Built-in Operators</h5>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Operator</th>
<th class="tableblock halign-left valign-top">Description</th>
<th class="tableblock halign-left valign-top">Examples</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Elvis</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Outputs the default value if the previous part cannot be resolved or resolves to <code>null</code>.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>{person.name ?: 'John'}</code>, <code>{person.name or 'John'}</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">Ternary</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Shorthand for if-then-else statement. Unlike in <a href="#if_section">If Section</a> nested operators are not supported.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>{item.isActive ? item.name : 'Inactive item'}</code> outputs the value of <code>item.name</code> if <code>item.isActive</code> resolves to <code>true</code>.</p></td>
</tr>
</tbody>
</table>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
The condition in a ternary operator evaluates to <code>true</code> if the value is not considered <code>falsy</code> as described in the <a href="#if_section">If Section</a>.
</td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In fact, the operators are implemented as "virtual methods" that consume one parameter and can be used with infix notation, i.e. <code>{person.name or 'John'}</code> is translated to <code>{person.name.or('John')}</code>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="character-escapes"><a class="anchor" href="#character-escapes"></a>2.3.1.5. Character Escapes</h5>
<div class="paragraph">
<p>For HTML and XML templates the <code>'</code>, <code>"</code>, <code>&lt;</code>, <code>&gt;</code>, <code>&amp;</code> characters are escaped by default.
If you need to render the unescaped value:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Use the <code>raw</code> or <code>safe</code> properties implemented as extension methods of the <code>java.lang.Object</code>,</p>
</li>
<li>
<p>Wrap the <code>String</code> value in a <code>io.quarkus.qute.RawString</code>.</p>
</li>
</ol>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
&lt;h1&gt;{title}&lt;/h1&gt; <i class="conum" data-value="1"></i><b>(1)</b>
{paragraph.raw} <i class="conum" data-value="2"></i><b>(2)</b>
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>title</code> that resolves to <code>Expressions &amp; Escapes</code> will be rendered as <code>Expressions &amp;amp; Escapes</code></td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td><code>paragraph</code> that resolves to <code>&lt;p&gt;My text!&lt;/p&gt;</code> will be rendered as <code>&lt;p&gt;My text!&lt;/p&gt;</code></td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="virtual-methods"><a class="anchor" href="#virtual-methods"></a>2.3.1.6. Virtual Methods</h5>
<div class="paragraph">
<p>A virtual method is a <strong>part of an expression</strong> that looks like a regular Java method invocation.
It&#8217;s called "virtual" because it does not have to match the actual method of a Java class.
In fact, like normal properties a virtual method is also handled by a value resolver.
The only difference is that for virtual methods a value resolver consumes parameters that are also expressions.</p>
</div>
<div class="listingblock">
<div class="title">Virtual Method Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
&lt;h1&gt;{item.buildName(item.name,5)}&lt;/h1&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>buildName(item.name,5)</code> represents a virtual method with name <code>buildName</code> and two parameters: <code>item.name</code> and <code>5</code> . The virtual method could be evaluated by a value resolver generated for the following Java class:
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">class Item {
   String buildName(String name, int age) {
      return name + ":" + age;
   }
}</code></pre>
</div>
</div></td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Virtual methods are usually evaluated by value resolvers generated for <a href="#template_extension_methods">@TemplateExtension methods</a>, <a href="#template_data">@TemplateData</a> or classes used in <a href="#parameter_declarations">parameter declarations</a>. However, a custom value resolver that is not backed by any Java class/method can be registered as well.
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>A virtual method with single parameter can be called using the infix notation:</p>
</div>
<div class="listingblock">
<div class="title">Infix Notation Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
&lt;p&gt;{item.price or 5}&lt;/p&gt;  <i class="conum" data-value="1"></i><b>(1)</b>
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>item.price or 5</code> is translated to <code>item.price.or(5)</code>.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Virtual method parameters can be "nested" virtual method invocations.</p>
</div>
<div class="listingblock">
<div class="title">Nested Virtual Method Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
&lt;p&gt;{item.subtractPrice(item.calculateDiscount(10))}&lt;/p&gt;  <i class="conum" data-value="1"></i><b>(1)</b>
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>item.calculateDiscount(10)</code> is evaluated first and then passed as an argument to <code>item.subtractPrice()</code>.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect3">
<h4 id="sections"><a class="anchor" href="#sections"></a>2.3.2. Sections</h4>
<div class="paragraph">
<p>A section:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>has a start tag</p>
<div class="ulist">
<ul>
<li>
<p>starts with <code>#</code>, followed by the name of the section such as <code>{#if}</code> and <code>{#each}</code>,</p>
</li>
</ul>
</div>
</li>
<li>
<p>may be empty</p>
<div class="ulist">
<ul>
<li>
<p>tag ends with <code>/</code>, ie. <code>{#emptySection /}</code></p>
</li>
</ul>
</div>
</li>
<li>
<p>may contain other expression, sections, etc.</p>
<div class="ulist">
<ul>
<li>
<p>the end tag starts with <code>/</code> and contains the name of the section (optional): <code>{#if foo}Foo!{/if}</code> or <code>{#if foo}Foo!{/}</code>,</p>
</li>
</ul>
</div>
</li>
</ul>
</div>
<div class="paragraph">
<p>The start tag can also define parameters.
The parameters have optional names.
A section may contain several content <strong>blocks</strong>.
The "main" block is always present.
Additional/nested blocks also start with <code>#</code> and can have parameters too - <code>{#else if item.isActive}</code>.
A section helper that defines the logic of a section can "execute" any of the blocks and evaluate the parameters.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#if item.name is 'sword'}
  It's a sword!
{#else if item.name is 'shield'}
  It's a shield!
{#else}
  Item is neither a sword nor a shield.
{/if}</code></pre>
</div>
</div>
<div class="sect4">
<h5 id="loop-section"><a class="anchor" href="#loop-section"></a>2.3.2.1. Loop Section</h5>
<div class="paragraph">
<p>The loop section makes it possible to iterate over an instance of <code>Iterable</code>, <code>Map</code> 's entry set, <code>Stream</code> and an Integer.
It has two flavors.
The first one is using the <code>each</code> name alias.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#each items}
  {it.name} <i class="conum" data-value="1"></i><b>(1)</b>
{/each}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>it</code> is an implicit alias. <code>name</code> is resolved against the current iteration element.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The other form is using the <code>for</code> name alias and can specify the alias used to reference the iteration element:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#for item in items}
  {item.name}
{/for}</code></pre>
</div>
</div>
<div class="paragraph">
<p>It&#8217;s also possible to access the iteration metadata inside the loop:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#each items}
  {count}. {it.name} <i class="conum" data-value="1"></i><b>(1)</b>
{/each}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>count</code> represents one-based index. Metadata also include zero-based <code>index</code>, <code>hasNext</code>, <code>odd</code>, <code>even</code>.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The <code>for</code> statement also works with integers, starting from 1. In the example below, considering that <code>total = 3</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#for i in total}
  {i}:
{/for}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The output will be:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">1:2:3:</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="if_section"><a class="anchor" href="#if_section"></a>2.3.2.2. If Section</h5>
<div class="paragraph">
<p>The <code>if</code> section represents a basic control flow section.
The simplest possible version accepts a single parameter and renders the content if the condition is evaluated to <code>true</code>.
A condition without an operator evaluates to <code>true</code> if the value is not considered <code>falsy</code>, i.e. if the value is not <code>null</code>, <code>false</code>, an empty collection, an empty map, an empty array, an empty string/char sequence or a number equal to zero.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#if item.active}
  This item is active.
{/if}</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also use the following operators in a condition:</p>
</div>
<table class="tableblock frame-all grid-all stretch">
<colgroup>
<col style="width: 33.3333%;">
<col style="width: 33.3333%;">
<col style="width: 33.3334%;">
</colgroup>
<thead>
<tr>
<th class="tableblock halign-left valign-top">Operator</th>
<th class="tableblock halign-left valign-top">Aliases</th>
<th class="tableblock halign-left valign-top">Precedence (higher wins)</th>
</tr>
</thead>
<tbody>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">logical complement</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>!</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">4</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">greater than</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>gt</code>, <code>&gt;</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">greater than or equal to</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ge</code>, <code>&gt;=</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">less than</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>lt</code>, <code>&lt;</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">less than or equal to</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>le</code>, <code>&lt;=</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">3</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">equals</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>eq</code>, <code>==</code>, <code>is</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">not equals</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>ne</code>, <code>!=</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">2</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">logical AND (short-circuiting)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>&amp;&amp;</code>, <code>and</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">logical OR (short-circuiting)</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock"><code>||</code>, <code>or</code></p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">1</p></td>
</tr>
</tbody>
</table>
<div class="listingblock">
<div class="title">A simple operator example</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#if item.age &gt; 10}
  This item is very old.
{/if}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Multiple conditions are also supported.</p>
</div>
<div class="listingblock">
<div class="title">Multiple conditions example</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#if item.age &gt; 10 &amp;&amp; item.price &gt; 500}
  This item is very old and expensive.
{/if}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Precedence rules can be overridden by parentheses.</p>
</div>
<div class="listingblock">
<div class="title">Parentheses example</div>
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#if (item.age &gt; 10 || item.price &gt; 500) &amp;&amp; user.loggedIn}
  User must be logged in and item age must be &gt; 10 or price must be &gt; 500.
{/if}</code></pre>
</div>
</div>
<div class="paragraph">
<p>You can also add any number of <code>else</code> blocks:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#if item.age &gt; 10}
  This item is very old.
{#else if item.age &gt; 5}
  This item is quite old.
{#else if item.age &gt; 2}
  This item is old.
{#else}
  This item is not old at all!
{/if}</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="with-section"><a class="anchor" href="#with-section"></a>2.3.2.3. With Section</h5>
<div class="paragraph">
<p>This section can be used to set the current context object.
This could be useful to simplify the template structure:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{#with item.parent}
  &lt;h1&gt;{name}&lt;/h1&gt;  <i class="conum" data-value="1"></i><b>(1)</b>
  &lt;p&gt;{description}&lt;/p&gt; <i class="conum" data-value="2"></i><b>(2)</b>
{/with}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The <code>name</code> will be resolved against the <code>item.parent</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The <code>description</code> will be also resolved against the <code>item.parent</code>.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>This section might also come in handy when we&#8217;d like to avoid multiple expensive invocations:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{#with item.callExpensiveLogicToGetTheValue(1,'foo',bazinga)}
  {#if this is "fun"} <i class="conum" data-value="1"></i><b>(1)</b>
    &lt;h1&gt;Yay!&lt;/h1&gt;
  {#else}
    &lt;h1&gt;{this} is not fun at all!&lt;/h1&gt;
  {/if}
{/with}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>this</code> is the result of <code>item.callExpensiveLogicToGetTheValue(1,'foo',bazinga)</code>. The method is only invoked once even though the result may be used in multiple expressions.</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="letset-section"><a class="anchor" href="#letset-section"></a>2.3.2.4. Let/Set Section</h5>
<div class="paragraph">
<p>This section allows you to define named local variables:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{#let myParent=order.item.parent}
  &lt;h1&gt;{myParent.name}&lt;/h1&gt;
{/let}</code></pre>
</div>
</div>
<div class="paragraph">
<p>The section tag is also registered under the <code>set</code> alias:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{#set myParent=item.parent price=item.price}
  &lt;h1&gt;{myParent.name}&lt;/h1&gt;
  &lt;p&gt;Price: {price}
{/set}</code></pre>
</div>
</div>
</div>
<div class="sect4">
<h5 id="include_helper"><a class="anchor" href="#include_helper"></a>2.3.2.5. Include/Insert Sections</h5>
<div class="paragraph">
<p>These sections can be used to include another template and possibly override some parts of the template (template inheritance).</p>
</div>
<div class="listingblock">
<div class="title">Template "base"</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;html&gt;
&lt;head&gt;
&lt;meta charset="UTF-8"&gt;
&lt;title&gt;{#insert title}Default Title{/}&lt;/title&gt; <i class="conum" data-value="1"></i><b>(1)</b>
&lt;/head&gt;
&lt;body&gt;
  {#insert body}No body!{/} <i class="conum" data-value="2"></i><b>(2)</b>
&lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>insert</code> sections are used to specify parts that could be overridden by a template that includes the given template.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>An <code>insert</code> section may define the default content that is rendered if not overridden.</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="title">Template "detail"</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{#include base} <i class="conum" data-value="1"></i><b>(1)</b>
  {#title}My Title{/title} <i class="conum" data-value="2"></i><b>(2)</b>
  {#body}
    &lt;div&gt;
      My body.
    &lt;/div&gt;
  {/body}
{/include}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>include</code> section is used to specify the extended template.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Nested blocks are used to specify the parts that should be overridden.</td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Section blocks can also define an optional end tag - <code>{/title}</code>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect4">
<h5 id="user_tags"><a class="anchor" href="#user_tags"></a>2.3.2.6. User-defined Tags</h5>
<div class="paragraph">
<p>User-defined tags can be used to include a template and optionally pass some parameters.
Let&#8217;s suppose we have a template called <code>itemDetail.html</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code class="language-none hljs">{#if showImage} <i class="conum" data-value="1"></i><b>(1)</b>
  {it.image} <i class="conum" data-value="2"></i><b>(2)</b>
  {nested-content} <i class="conum" data-value="3"></i><b>(3)</b>
{/if}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>showImage</code> is a named parameter.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td><code>it</code> is a special key that is replaced with the first unnamed param of the tag.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>(optional) <code>nested-content</code> is a special key that will be replaced by the content of the tag.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Now if we register this template under the name <code>itemDetail.html</code> and if we add a <code>UserTagSectionHelper</code> to the engine:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">Engine engine = Engine.builder()
                   .addSectionHelper(new UserTagSectionHelper.Factory("itemDetail","itemDetail.html"))
                   .build();</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In Quarkus, all files from the <code>src/main/resources/templates/tags</code> are registered and monitored automatically!
</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>We can include the tag like this:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">&lt;ul&gt;
{#for item in items}
  &lt;li&gt;
  {#itemDetail item showImage=true} <i class="conum" data-value="1"></i><b>(1)</b>
    = &lt;b&gt;{item.name}&lt;/b&gt; <i class="conum" data-value="2"></i><b>(2)</b>
  {/itemDetail}
  &lt;/li&gt;
{/for}
&lt;/ul&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>item</code> is resolved to an iteration element and can be referenced using the <code>it</code> key in the tag template.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Tag content injected using the <code>nested-content</code> key in the tag template.</td>
</tr>
</table>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="engine-configuration"><a class="anchor" href="#engine-configuration"></a>2.4. Engine Configuration</h3>
<div class="sect3">
<h4 id="template-locator"><a class="anchor" href="#template-locator"></a>2.4.1. Template Locator</h4>
<div class="paragraph">
<p>Manual registration is sometimes handy but it&#8217;s also possible to register a template locator using <code>EngineBuilder.addLocator(Function&lt;String, Optional&lt;Reader&gt;&gt;)</code>.
This locator is used whenever the <code>Engine.getTemplate()</code> method is called and the engine has no template for a given id stored in the cache.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
In Quarkus, all templates from the <code>src/main/resources/templates</code> are located automatically.
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="quarkus_integration"><a class="anchor" href="#quarkus_integration"></a>3. Quarkus Integration</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you want to use Qute in your Quarkus application add the following dependency to your project:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;dependency&gt;
    &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
    &lt;artifactId&gt;quarkus-qute&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>In Quarkus, a preconfigured engine instance is provided and available for injection - a bean with scope <code>@ApplicationScoped</code>, bean type <code>io.quarkus.qute.Engine</code> and qualifier <code>@Default</code> is registered automatically.
Moreover, all templates located in the <code>src/main/resources/templates</code> directory are validated and can be easily injected.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">import io.quarkus.qute.Engine;
import io.quarkus.qute.Template;
import io.quarkus.qute.api.ResourcePath;

class MyBean {

    @Inject
    Template items; <i class="conum" data-value="1"></i><b>(1)</b>

    @ResourcePath("detail/items2_v1.html") <i class="conum" data-value="2"></i><b>(2)</b>
    Template items2;

    @Inject
    Engine engine; <i class="conum" data-value="3"></i><b>(3)</b>
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>If there is no <code>ResourcePath</code> qualifier provided, the field name is used to locate the template. In this particular case, the container will attempt to locate a template with path <code>src/main/resources/templates/items.html</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The <code>ResourcePath</code> qualifier instructs the container to inject a template from a path relative from <code>src/main/resources/templates</code>. In this case, the full path is <code>src/main/resources/templates/detail/items2_v1.html</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Inject the configured <code>Engine</code> instance.</td>
</tr>
</table>
</div>
<div class="sect2">
<h3 id="template-variants"><a class="anchor" href="#template-variants"></a>3.1. Template Variants</h3>
<div class="paragraph">
<p>Sometimes it&#8217;s useful to render a specific variant of the template based on the content negotiation.
This can be done by setting a special attribute via <code>TemplateInstance.setAttribute()</code>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">class MyService {

    @Inject
    Template items; <i class="conum" data-value="1"></i><b>(1)</b>

    @Inject
    ItemManager manager;

    String renderItems() {
       return items.data("items",manager.findItems()).setAttribute(TemplateInstance.SELECTED_VARIANT, new Variant(Locale.getDefault(),"text/html","UTF-8")).render();
    }
}</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
When using <code>quarkus-resteasy-qute</code> the content negotiation is performed automatically. See <a href="#resteasy_integration">RESTEasy Integration</a>.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="injecting-beans-directly-in-templates"><a class="anchor" href="#injecting-beans-directly-in-templates"></a>3.2. Injecting Beans Directly In Templates</h3>
<div class="paragraph">
<p>A CDI bean annotated with <code>@Named</code> can be referenced in any template through the <code>inject</code> namespace:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{inject:foo.price} <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>First, a bean with name <code>foo</code> is found and then used as the base object.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>All expressions using the <code>inject</code> namespace are validated during build.
For the expression <code>inject:foo.price</code> the implementation class of the injected bean must either have the <code>price</code> property (e.g. a <code>getPrice()</code> method) or a matching <a href="#template_extension_methods">template extension method</a> must exist.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
A <code>ValueResolver</code> is also generated for all beans annotated with <code>@Named</code> so that it&#8217;s possible to access its properties without reflection.
</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="parameter_declarations"><a class="anchor" href="#parameter_declarations"></a>3.3. Parameter Declarations</h3>
<div class="paragraph">
<p>It is possible to specify optional parameter declarations in a template.
Quarkus attempts to validate all expressions that reference such parameters.
If an invalid/incorrect expression is found the build fails.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{@org.acme.Foo foo} <i class="conum" data-value="1"></i><b>(1)</b>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="UTF-8"&gt;
&lt;title&gt;Qute Hello&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;h1&gt;{title}&lt;/h1&gt; <i class="conum" data-value="2"></i><b>(2)</b>
  Hello {foo.message}! <i class="conum" data-value="3"></i><b>(3)</b>
&lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Parameter declaration - maps <code>foo</code> to <code>org.acme.Foo</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Not validated - not matching a param declaration.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>This expression is validated. <code>org.acme.Foo</code> must have a property <code>message</code> or a matching template extension method must exist.</td>
</tr>
</table>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
A value resolver is also generated for all types used in parameter declarations so that it&#8217;s possible to access its properties without reflection.
</td>
</tr>
</table>
</div>
<div class="sect3">
<h4 id="overriding-parameter-declarations"><a class="anchor" href="#overriding-parameter-declarations"></a>3.3.1. Overriding Parameter Declarations</h4>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{@org.acme.Foo foo}
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="UTF-8"&gt;
&lt;title&gt;Qute Hello&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;h1&gt;{foo.message}&lt;/h1&gt; <i class="conum" data-value="1"></i><b>(1)</b>
  {#for foo in baz.foos}
    &lt;p&gt;Hello {foo.message}!&lt;/p&gt; <i class="conum" data-value="2"></i><b>(2)</b>
  {/for}
&lt;/body&gt;
&lt;/html&gt;</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Validated against <code>org.acme.Foo</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Not validated - <code>foo</code> is overridden in the loop section.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect2">
<h3 id="template_extension_methods"><a class="anchor" href="#template_extension_methods"></a>3.4. Template Extension Methods</h3>
<div class="paragraph">
<p>Extension methods can be used to extend the data classes with new functionality or resolve expressions for a specific <a href="#namespace_extension_methods">namespace</a>.
For example, it is possible to add <em>computed properties</em> and <em>virtual methods</em>.</p>
</div>
<div class="paragraph">
<p>A value resolver is automatically generated for a method annotated with <code>@TemplateExtension</code>.
If a  class is annotated with <code>@TemplateExtension</code> then a value resolver is generated for every method declared on the class.
Methods that do not meet the following requirements are ignored.</p>
</div>
<div class="paragraph">
<p>A template extension method:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>must not be <code>private</code></p>
</li>
<li>
<p>must be static,</p>
</li>
<li>
<p>must not return <code>void</code>,</p>
</li>
<li>
<p>must accept at least one parameter, unless the namespace is specified.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p>The class of the first parameter is used to match the base object unless the namespace is specified.
In such case, the namespace is used to match an expression.
The method name is used to match the property name by default.
However, it is possible to specify the matching name with <code>TemplateExtension#matchName()</code>.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
A special constant - <code>TemplateExtension#ANY</code> - may be used to specify that the extension method matches any name. In that case, a method parameter is used to pass the property name.
If a namespace is specified the method must declare at least one parameter and the first parameter must be a string.
If no namespace is specified the method must declare at least two parameters and the second parameter must be a string.
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="title">Extension Method Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme;

class Item {

    public final BigDecimal price;

    public Item(BigDecimal price) {
        this.price = price;
    }
}

@TemplateExtension
class MyExtensions {

    static BigDecimal discountedPrice(Item item) { <i class="conum" data-value="1"></i><b>(1)</b>
        return item.getPrice().multiply(new BigDecimal("0.9"));
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This method matches an expression with base object of the type <code>Item.class</code> and the <code>discountedPrice</code> property name.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>This template extension method makes it possible to render the following template:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{item.discountedPrice} <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>item</code> is resolved to an instance of <code>org.acme.Item</code>.</td>
</tr>
</table>
</div>
<div class="sect3">
<h4 id="method-parameters"><a class="anchor" href="#method-parameters"></a>3.4.1. Method Parameters</h4>
<div class="paragraph">
<p>An extension method may accept multiple parameters.
If no namespace is specified the first parameter is always used to pass the base object, i.e. <code>org.acme.Item</code> in the first example.
Other parameters are resolved when rendering the template and passed to the extension method.</p>
</div>
<div class="listingblock">
<div class="title">Multiple Parameters Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@TemplateExtension
class BigDecimalExtensions {

    static BigDecimal scale(BigDecimal val, int scale, RoundingMode mode) { <i class="conum" data-value="1"></i><b>(1)</b>
        return val.setScale(scale, mode);
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>This method matches an expression with base object of the type <code>BigDecimal.class</code>, with the <code>scale</code> virtual method name and two virtual method parameters.</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{item.discountedPrice.scale(2,mode)} <i class="conum" data-value="1"></i><b>(1)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>item.discountedPrice</code> is resolved to an instance of <code>BigDecimal</code>.</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="namespace_extension_methods"><a class="anchor" href="#namespace_extension_methods"></a>3.4.2. Namespace Extention Methods</h4>
<div class="paragraph">
<p>If <code>TemplateExtension#namespace()</code> is specified then the extension method is used to resolve expressions with the given <a href="#expressions">namespace</a>.
Template extension methods that share the same namespace are grouped in one resolver ordered by <code>TemplateExtension#priority()</code>.
The first matching extension method is used to resolve an expression.</p>
</div>
<div class="listingblock">
<div class="title">Namespace Extension Method Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@TemplateExtension(namespace = "str")
public static class StringExtensions {

   static String format(String fmt, Object... args) {
      return String.format(fmt, args);
   }

   static String reverse(String val) {
      return new StringBuilder(val).reverse().toString();
   }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>These extension methods can be used as follows.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{str:format('%s %s!','Hello', 'world')} <i class="conum" data-value="1"></i><b>(1)</b>
{str:reverse('hello')} <i class="conum" data-value="2"></i><b>(2)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The output is <code>Hello world!</code></td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The output is <code>olleh</code></td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="built-in-template-extension"><a class="anchor" href="#built-in-template-extension"></a>3.4.3. Built-in Template Extension</h4>
<div class="paragraph">
<p>Quarkus provides a set of built-in extension methods.</p>
</div>
<div class="sect4">
<h5 id="map-extension-methods"><a class="anchor" href="#map-extension-methods"></a>3.4.3.1. Map extension methods:</h5>
<div class="ulist">
<ul>
<li>
<p><code>keys</code> or <code>keySet</code>: Returns a Set view of the keys contained in a map</p>
<div class="ulist">
<ul>
<li>
<p><code>{#for key in map.keySet}</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>values</code>: Returns a Collection view of the values contained in a map</p>
<div class="ulist">
<ul>
<li>
<p><code>{#for value in map.values}</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>size</code>: Returns the number of key-value mappings in a map</p>
<div class="ulist">
<ul>
<li>
<p><code>{map.size}</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>isEmpty</code>: Returns true if a map contains no key-value mappings</p>
<div class="ulist">
<ul>
<li>
<p><code>{#if map.isEmpty}</code></p>
</li>
</ul>
</div>
</li>
<li>
<p><code>get(key)</code>: Returns the value to which the specified key is mapped</p>
<div class="ulist">
<ul>
<li>
<p><code>{map.get('foo')}</code> or <code>{map['foo']}</code></p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="collection-extension-methods"><a class="anchor" href="#collection-extension-methods"></a>3.4.3.2. Collection extension methods:</h5>
<div class="ulist">
<ul>
<li>
<p><code>get(index)</code>: Returns the element at the specified position in a list</p>
<div class="ulist">
<ul>
<li>
<p><code>{list.get(0)}</code> or <code>{list[0]}</code></p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="sect4">
<h5 id="number-extension-methods"><a class="anchor" href="#number-extension-methods"></a>3.4.3.3. Number extension methods:</h5>
<div class="ulist">
<ul>
<li>
<p><code>mod</code>: Modulo operation</p>
<div class="ulist">
<ul>
<li>
<p><code>{#if counter.mod(5) == 0}</code></p>
</li>
</ul>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>
<div class="sect2">
<h3 id="template_data"><a class="anchor" href="#template_data"></a>3.5. @TemplateData</h3>
<div class="paragraph">
<p>A value resolver is automatically generated for a type annotated with <code>@TemplateData</code>.
This allows Quarkus to avoid using reflection to access the data at runtime.</p>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
Non-public members, constructors, static initializers, static, synthetic and void methods are always ignored.
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme;

@TemplateData
class Item {

    public final BigDecimal price;

    public Item(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getDiscountedPrice() {
        return price.multiply(new BigDecimal("0.9"));
    }
}</code></pre>
</div>
</div>
<div class="paragraph">
<p>Any instance of <code>Item</code> can be used directly in the template:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{#each items} <i class="conum" data-value="1"></i><b>(1)</b>
  {it.price} / {it.discountedPrice}
{/each}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td><code>items</code> is resolved to a list of <code>org.acme.Item</code> instances.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Furthermore, <code>@TemplateData.properties()</code> and <code>@TemplateData.ignore()</code> can be used to fine-tune the generated resolver.
Finally, it is also possible to specify the "target" of the annotation - this could be useful for third-party classes not controlled by the application:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@TemplateData(target = BigDecimal.class)
@TemplateData
class Item {

    public final BigDecimal price;

    public Item(BigDecimal price) {
        this.price = price;
    }
}</code></pre>
</div>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="html" class="language-html hljs">{#each items} <i class="conum" data-value="1"></i><b>(1)</b>
  {it.price.setScale(2, rounding)} <i class="conum" data-value="1"></i><b>(1)</b>
{/each}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The generated value resolver knows how to invoke the <code>BigDecimal.setScale()</code> method.</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="resteasy_integration"><a class="anchor" href="#resteasy_integration"></a>3.6. RESTEasy Integration</h3>
<div class="paragraph">
<p>If you want to use Qute in your JAX-RS application, you&#8217;ll need to add the <code>quarkus-resteasy-qute</code> extension first.
In your <code>pom.xml</code> file, add:</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs">&lt;dependency&gt;
    &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
    &lt;artifactId&gt;quarkus-resteasy-qute&lt;/artifactId&gt;
&lt;/dependency&gt;</code></pre>
</div>
</div>
<div class="paragraph">
<p>This extension registers a special <code>ContainerResponseFilter</code> implementation so that a resource method can return a <code>TemplateInstance</code> and the filter takes care of all necessary steps.
A simple JAX-RS resource may look like this:</p>
</div>
<div class="listingblock">
<div class="title">HelloResource.java</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">package org.acme.quarkus.sample;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.Template;

@Path("hello")
public class HelloResource {

    @Inject
    Template hello; <i class="conum" data-value="1"></i><b>(1)</b>

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public TemplateInstance get(@QueryParam("name") String name) {
        return hello.data("name", name); <i class="conum" data-value="2"></i><b>(2)</b> <i class="conum" data-value="3"></i><b>(3)</b>
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>If there is no <code>@ResourcePath</code> qualifier provided, the field name is used to locate the template. In this particular case, we&#8217;re injecting a template with path <code>templates/hello.txt</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td><code>Template.data()</code> returns a new template instance that can be customized before the actual rendering is triggered. In this case, we put the name value under the key <code>name</code>. The data map is accessible during rendering.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>Note that we don&#8217;t trigger the rendering - this is done automatically by a special <code>ContainerResponseFilter</code> implementation.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>The content negotiation is performed automatically.
The resulting output depends on the <code>Accept</code> header received from the client.</p>
</div>
<div class="listingblock">
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@Path("/detail")
class DetailResource {

    @Inject
    Template item; <i class="conum" data-value="1"></i><b>(1)</b>

    @GET
    @Produces({ MediaType.TEXT_HTML, MediaType.TEXT_PLAIN })
    public TemplateInstance item() {
        return item.data("myItem", new Item("Alpha", 1000)); <i class="conum" data-value="2"></i><b>(2)</b>
    }
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Inject a variant template with base path derived from the injected field - <code>src/main/resources/templates/item</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>For <code>text/plain</code> the <code>src/main/resources/templates/item.txt</code> template is used. For <code>text/html</code> the <code>META-INF/resources/templates/item.html</code> template is used.</td>
</tr>
</table>
</div>
</div>
<div class="sect2">
<h3 id="development-mode"><a class="anchor" href="#development-mode"></a>3.7. Development Mode</h3>
<div class="paragraph">
<p>In the development mode, all files located in <code>src/main/resources/templates</code> are watched for changes and modifications are immediately visible.</p>
</div>
</div>
<div class="sect2">
<h3 id="type-safe-message-bundles"><a class="anchor" href="#type-safe-message-bundles"></a>3.8. Type-safe Message Bundles</h3>
<div class="sect3">
<h4 id="basic-concepts"><a class="anchor" href="#basic-concepts"></a>3.8.1. Basic Concepts</h4>
<div class="paragraph">
<p>The basic idea is that every message is potentially a very simple template.
In order to prevent type errors a message is defined as an annotated method of a <strong>message bundle interface</strong>.
Quarkus generates the <strong>message bundle implementation</strong> at build time.
Subsequently, the bundles can be used at runtime:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Directly in your code via <code>io.quarkus.qute.i18n.MessageBundles#get()</code>; e.g. <code>MessageBundles.get(AppMessages.class).hello_name("Lucie")</code></p>
</li>
<li>
<p>Injected in your beans via <code>@Inject</code>; e.g. <code>@Inject AppMessages</code></p>
</li>
<li>
<p>Referenced in the templates via the message bundle name; e.g. <code>{msg:hello_name('Lucie')}</code></p>
</li>
</ol>
</div>
<div class="listingblock">
<div class="title">Message Bundle Interface Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">import io.quarkus.qute.i18n.Message;
import io.quarkus.qute.i18n.MessageBundle;

@MessageBundle <i class="conum" data-value="1"></i><b>(1)</b>
public interface AppMessages {

    @Message("Hello {name}!") <i class="conum" data-value="2"></i><b>(2)</b>
    String hello_name(String name); <i class="conum" data-value="3"></i><b>(3)</b>
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Denotes a message bundle interface. The bundle name is defaulted to <code>msg</code> and is used as a namespace in templates expressions, e.g. <code>{msg:hello_name}</code>.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Each method must be annotated with <code>@Message</code>. The value is a qute template.</td>
</tr>
<tr>
<td><i class="conum" data-value="3"></i><b>3</b></td>
<td>The method parameters can be used in the template.</td>
</tr>
</table>
</div>
</div>
<div class="sect3">
<h4 id="bundle-name-and-message-keys"><a class="anchor" href="#bundle-name-and-message-keys"></a>3.8.2. Bundle Name and Message Keys</h4>
<div class="paragraph">
<p>Keys are used directly in templates.
The bundle name is used as a namespace in template expressions.
The <code>@MessageBundle</code> can be used to define the default strategy used to generate message keys from method names.
However, the <code>@Message</code> can override this strategy and even define a custom key.
By default, the annotated element&#8217;s name is used as-is.
Other possibilities are:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>De-camel-cased and hyphenated; e.g. <code>helloName()</code> &#8594; <code>hello-name</code></p>
</li>
<li>
<p>De-camel-cased and parts separated by underscores; e.g. <code>helloName()</code> &#8594; <code>hello_name</code>.</p>
</li>
</ol>
</div>
</div>
<div class="sect3">
<h4 id="validation"><a class="anchor" href="#validation"></a>3.8.3. Validation</h4>
<div class="ulist">
<ul>
<li>
<p>All message bundle templates are validated:</p>
<div class="ulist">
<ul>
<li>
<p>All expressions without a namespace must map to a parameter; e.g. <code>Hello {foo}</code> &#8594; the method must have a param of name <code>foo</code></p>
</li>
<li>
<p>All expressions are validated against the types of the parameters; e.g. <code>Hello {foo.bar}</code> where the parameter <code>foo</code> is of type <code>org.acme.Foo</code> &#8594; <code>org.acme.Foo</code> must have a property of name <code>bar</code></p>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
A warning message is logged for each <em>unused</em> parameter.
</td>
</tr>
</table>
</div>
</li>
</ul>
</div>
</li>
<li>
<p>Expressions that reference a message bundle method, such as <code>{msg:hello(item.name)}</code>, are validated too.</p>
</li>
</ul>
</div>
</div>
<div class="sect3">
<h4 id="localization"><a class="anchor" href="#localization"></a>3.8.4. Localization</h4>
<div class="paragraph">
<p>The default locale of the Java Virtual Machine used to <strong>build the application</strong> is used for the <code>@MessageBundle</code> interface by default.
However, the <code>io.quarkus.qute.i18n.MessageBundle#locale()</code> can be used to specify a custom locale.
Additionaly, there are two ways to define a localized bundle:</p>
</div>
<div class="olist arabic">
<ol class="arabic">
<li>
<p>Create an interface that extends the default interface that is annotated with <code>@Localized</code></p>
</li>
<li>
<p>Create an UTF-8 encoded file located in <code>src/main/resources/messages</code>; e.g. <code>msg_de.properties</code>.</p>
</li>
</ol>
</div>
<div class="admonitionblock tip">
<table>
<tr>
<td class="icon">
<i class="fa icon-tip" title="Tip"></i>
</td>
<td class="content">
A localized interface is the preferred solution mainly due to the possibility of easy refactoring.
</td>
</tr>
</table>
</div>
<div class="listingblock">
<div class="title">Localized Interface Example</div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">import io.quarkus.qute.i18n.Localized;
import io.quarkus.qute.i18n.Message;

@Localized("de") <i class="conum" data-value="1"></i><b>(1)</b>
public interface GermanAppMessages {

    @Override
    @Message("Hallo {name}!") <i class="conum" data-value="2"></i><b>(2)</b>
    String hello_name(String name);
}</code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>The value is the locale tag string (IETF).</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>The value is the localized template.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>Message bundle files must be encoded in UTF-8.
The file name consists of the relevant bundle name (e.g. <code>msg</code>) and underscore followed by the locate tag (IETF).
The file format is very simple: each line represents either a key/value pair with the equals sign used as a separator or a comment (line starts with <code>#</code>).
Keys are mapped to method names from the corresponding message bundle interface.
Values represent the templates normally defined by <code>io.quarkus.qute.i18n.Message#value()</code>.
We use <code>.properties</code> suffix in our example because most IDEs and text editors support syntax highlighting of <code>.properties</code> files.
But in fact, the suffix could be anything.</p>
</div>
<div class="listingblock">
<div class="title">Localized File Example - <code>msg_de.properties</code></div>
<div class="content">
<pre class="highlightjs highlight"><code data-lang="properties" class="language-properties hljs">hello_name=Hallo {name}! <i class="conum" data-value="1"></i><b>(1)</b> <i class="conum" data-value="2"></i><b>(2)</b></code></pre>
</div>
</div>
<div class="colist arabic">
<table>
<tr>
<td><i class="conum" data-value="1"></i><b>1</b></td>
<td>Each line in a localized file represents a message template.</td>
</tr>
<tr>
<td><i class="conum" data-value="2"></i><b>2</b></td>
<td>Keys and values are separated by the equals sign.</td>
</tr>
</table>
</div>
</div>
</div>
<div class="sect2">
<h3 id="configuration-reference"><a class="anchor" href="#configuration-reference"></a>3.9. Configuration Reference</h3>
<div class="paragraph configuration-legend">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> Configuration property fixed at build time - All other configuration properties are overridable at runtime</p>
</div>
<table class="tableblock frame-all grid-all stretch configuration-reference searchable">
<colgroup>
<col style="width: 80%;">
<col style="width: 10%;">
<col style="width: 10%;">
</colgroup>
<tbody>
<tr>
<th class="tableblock halign-left valign-top"><p class="tableblock"><a id="quarkus-qute_configuration"></a><a href="#quarkus-qute_configuration">Configuration property</a></p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Type</p></th>
<th class="tableblock halign-left valign-middle"><p class="tableblock">Default</p></th>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-qute_quarkus.qute.suffixes"></a><code><a href="#quarkus-qute_quarkus.qute.suffixes">quarkus.qute.suffixes</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The set of suffixes used when attempting to locate a template file.</p>
</div>
<div class="paragraph">
<p>By default, <code>engine.getTemplate("foo")</code> would result in several lookups: <code>foo</code>, <code>foo.html</code>, <code>foo.txt</code>, etc.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">list of string</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>qute.html,qute.txt,html,txt</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-qute_quarkus.qute.remove-standalone-lines"></a><code><a href="#quarkus-qute_quarkus.qute.remove-standalone-lines">quarkus.qute.remove-standalone-lines</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>Specify whether the parser should remove standalone lines from the output. A standalone line is a line that contains only section tags, parameter declarations and whitespace characters.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">boolean</p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>true</code></p></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><div class="content"><div class="paragraph">
<p><span class="icon"><i class="fa fa-lock" title="Fixed at build time"></i></span> <a id="quarkus-qute_quarkus.qute.content-types-content-types"></a><code><a href="#quarkus-qute_quarkus.qute.content-types-content-types">quarkus.qute.content-types</a></code></p>
</div>
<div class="openblock description">
<div class="content">
<div class="paragraph">
<p>The additional map of suffixes to content types. This map is used when working with template variants. By default, the <code>java.net.URLConnection#getFileNameMap()</code> is used to determine the content type of a template file.</p>
</div>
</div>
</div></div></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock"><code>Map&lt;String,String&gt;</code></p></td>
<td class="tableblock halign-left valign-middle"><p class="tableblock">required <span class="icon"><i class="fa fa-exclamation-circle" title="Configuration property is required"></i></span></p></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
    </div>
  </div>
</div>

  </div>

  <div class="content project-footer">
  <div class="footer-section">
    <div class="logo-wrapper">
      <a href="/"><img src="/assets/images/quarkus_logo_horizontal_rgb_reverse.svg" class="project-logo" title="Quarkus"></a>
    </div>
  </div>
  <div class="grid-wrapper">
    <p class="grid__item width-3-12">Quarkus is open. All dependencies of this project are available under the <a href='https://www.apache.org/licenses/LICENSE-2.0' target='_blank'>Apache Software License 2.0</a> or compatible license.<br /><br />This website was built with <a href='https://jekyllrb.com/' target='_blank'>Jekyll</a>, is hosted on <a href='https://pages.github.com/' target='_blank'>Github Pages</a> and is completely open source. If you want to make it better, <a href='https://github.com/quarkusio/quarkusio.github.io' target='_blank'>fork the website</a> and show us what you’ve got.</p>

    
      <div class="width-1-12 project-links">
        <span>Navigation</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="/">Home</a></li>
          
            <li><a href="/guides">Guides</a></li>
          
            <li><a href="/community/#contributing">Contribute</a></li>
          
            <li><a href="/faq">FAQ</a></li>
          
            <li><a href="/get-started">Get Started</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Contribute</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://twitter.com/quarkusio">Follow us</a></li>
          
            <li><a href="https://github.com/quarkusio">GitHub</a></li>
          
            <li><a href="/security">Security&nbsp;policy</a></li>
          
        </ul>
      </div>
    
      <div class="width-1-12 project-links">
        <span>Get Help</span>
        <ul class="footer-links width-1-12">
          
            <li><a href="https://groups.google.com/forum/#!forum/quarkus-dev">Forums</a></li>
          
            <li><a href="https://quarkusio.zulipchat.com">Chatroom</a></li>
          
        </ul>
      </div>
    

    
      <div class="width-3-12 more-links">
        <span>Quarkus is made of community projects</span>
        <ul class="footer-links">
          
            <li><a href="https://vertx.io/" target="_blank">Eclipse Vert.x</a></li>
          
            <li><a href="https://microprofile.io" target="_blank">Eclipse MicroProfile</a></li>
          
            <li><a href="https://hibernate.org" target="_blank">Hibernate</a></li>
          
            <li><a href="https://netty.io" target="_blank">Netty</a></li>
          
            <li><a href="https://resteasy.github.io" target="_blank">RESTEasy</a></li>
          
            <li><a href="https://camel.apache.org" target="_blank">Apache Camel</a></li>
          
            <li><a href="https://code.quarkus.io/" target="_blank">And many more...</a></li>
          
        </ul>
      </div>
    
  </div>
</div>
  <div class="content redhat-footer">
  <div class="grid-wrapper">
    <span class="licence">
      <i class="fab fa-creative-commons"></i><i class="fab fa-creative-commons-by"></i> <a href="https://creativecommons.org/licenses/by/3.0/" target="_blank">CC by 3.0</a> | <a href="https://www.redhat.com/en/about/privacy-policy">Privacy Policy</a>
    </span>
    <span class="redhat">
      Sponsored by
    </span>
    <span class="redhat-logo">
      <a href="https://www.redhat.com/" target="_blank"><img src="/assets/images/redhat_reversed.svg"></a>
    </span>
  </div>
</div>


  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js" integrity="sha384-8gBf6Y4YYq7Jx97PIqmTwLPin4hxIzQw5aDmUg/DDhul9fFpbbLcLh3nTIIDJKhx" crossorigin="anonymous"></script>
  <script type="text/javascript" src="/assets/javascript/mobile-nav.js"></script>
  <script type="text/javascript" src="/assets/javascript/scroll-down.js"></script>
  <script src="/assets/javascript/satellite.js" type="text/javascript"></script>
  <script src="https://quarkus.io/guides/javascript/config.js" type="text/javascript"></script>
  <script src="/assets/javascript/search-filter.js" type="text/javascript"></script>
  <script src="/assets/javascript/back-to-top.js" type="text/javascript"></script>
</body>

</html>
